package com.example.bankend.controller;

import com.example.bankend.model.chatmessage;
import com.example.bankend.service.method.ChatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Api(tags = "AI聊天功能")
@RestController
@RequestMapping("/api/chat")
public class ChatController {
    @Autowired
    private ChatService chatService;

    // 发送用户消息并获取大模型响应
    @ApiOperation(value = "跟AI发送消息，实现对话")
    @PostMapping("/send")
    public chatmessage sendUserMessage(@RequestBody chatmessage userMessage) {
        // 保存用户消息
        chatService.saveUserMessage(userMessage);
        // 获取大模型响应
        return chatService.getResponseFromAi(userMessage);
    }

    // 获取所有对话历史
    @ApiOperation(value = "获取对话历史")
    @GetMapping("/history")
    public List<chatmessage> getChatHistory() {
        return chatService.getAllChatHistory();
    }
}